/**
 编程题:函数柯里化
 function curry(func) {
  // something

}
 function sum(a, b, c) {
  return a + b + c;
}

 let curriedSum = curry(sum);


 console.log(curriedSum(1, 2, 3)); // 6, still callable normally
 console.log(curriedSum(1)(2, 3)); // 6, currying of 1st arg
 console.log(curriedSum(1)(2)(3)); // 6, full currying

 */


function curry(func) {
  return  function fn(...agrs) {
    if (agrs.length >= func.length) {
      return func.apply(this, agrs)
    } else {
      return function (...args2) {
        return fn.apply(this, agrs.concat(args2))
      }
    }
  }
}

function sum(a, b, c) {
  return a + b + c;
}

let curriedSum = curry(sum);


console.log(curriedSum(1, 2, 3)); // 6, still callable normally
console.log(curriedSum(1)(2, 3)); // 6, currying of 1st arg
console.log(curriedSum(1)(2)(3)); // 6, full currying
